package com.sfy.controller;

import com.sfy.pojo.Dept;
import com.sfy.pojo.Result;
import com.sfy.service.DeptService;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;
    //查询所有部门
    //@RequestMapping(value = "/depts",method = {RequestMethod.GET})
    @GetMapping
    public Result selectAllDept(){

        List<Dept> deptList = deptService.selectAllDept();
        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    public Result deleteDeptById(@PathVariable Integer id){
        deptService.deleteDeptById(id);
        return Result.success();
    }

    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        deptService.addDept(dept);
        return Result.success();
    }

    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }
}
